package org.example.beetlsql.mutiple.service;

import org.beetl.sql.core.SQLManager;
import org.example.beetlsql.mutiple.entity.UserInfo;
import org.example.beetlsql.mutiple.mapper.Db1Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 使用readOnly从库，
 * 其他情况使用主库
 *
 */
@Service
public class Db1Service {

	@Autowired
	SQLManager sqlManager;
	@Autowired
	Db1Mapper userInfoMapper;
	@Transactional(readOnly = true)
	public UserInfo queryUser(Integer id){
		//or
		//sqlManager.unique(UserInfo.class,id);
		return userInfoMapper.single(id);

	}

	@Transactional
	public UserInfo addUser(){
		UserInfo userInfo = new UserInfo();
		userInfo.setName("newUser");
		 userInfoMapper.insert(userInfo);
		 return userInfo;

	}


}
